package com.jiyun.order.controller;

import com.jiyun.order.service.OrderService;
import com.jiyun.pojo.order.OrderAppraise;
import com.jiyun.pojo.order.OrderComplaint;
import com.jiyun.pojo.order.vo.DriverVo;
import com.jiyun.pojo.order.vo.OrderVo;
import com.jiyun.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 订单列表
     *
     * @return
     */
    @GetMapping("/orderList")
    public Result list(String userId) {
        List<OrderVo> orderVo = orderService.list(userId);
        return Result.ok(orderVo);
    }

    /**
     * 查找某个订单详情
     *
     * @return
     */
    @GetMapping("/findOrderById")
    public Result findOrderById(String orderId) {
        OrderVo orderVo = orderService.findOrderById(orderId);
        return Result.ok(orderVo);
    }

    /**
     * 查找司机信息
     *
     * @return
     */
    @GetMapping("/findDriverById")
    public Result findDriverById(Integer driverId) {
        DriverVo driverVo = orderService.findDriverById(driverId);
        return Result.ok(driverVo);
    }

    /**
     * 添加订单的投诉内容
     *
     * @return
     */
    @PostMapping("/insertComplain")
    public Result insertComplain(@RequestBody OrderComplaint orderComplaint) {
        orderService.insertComplain(orderComplaint);
        return Result.ok();
    }

    /**
     * 查找订单投诉内容
     *
     * @return
     */
    @GetMapping("/getComplain")
    public Result getComplain(String orderId) {
        OrderComplaint orderComplaint = orderService.getComplain(orderId);
        return Result.ok(orderComplaint);
    }

    /**
     * 添加评论
     */
    @PostMapping("/insertUserAppraise")
    public Result insertUserAppraise(@RequestBody OrderAppraise orderAppraise) {
        orderService.insertUserAppraise(orderAppraise);
        return Result.ok();
    }

    /**
     * 查找订单评论
     */
    @GetMapping("/getUserAppraise")
    public Result getUserAppraise(String orderId) {
        OrderAppraise orderAppraise = orderService.getUserAppraise(orderId);
        return Result.ok(orderAppraise);
    }

    /**
     * 修改评论
     */
    @PutMapping("/UpdateUserAppraise")
    public Result UpdateUserAppraise(@RequestBody OrderAppraise orderAppraise) {
        orderService.UpdateUserAppraise(orderAppraise);
        return Result.ok();
    }

    /**
     * 支付完成修改订单状态
     */
    @GetMapping("/updateOrder")
    public Result updateOrder(String orderId) {
        //支付成功修改订单状态
        orderService.updateOrderStatus(orderId);
        return Result.ok();
    }
}
